package lgp1226;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long p = sc.nextLong();
		System.out.printf("%d^%d mod %d=%d",a,b,p,binpowmod(a,b,p));

	}
	
	//快速幂，结果对MOD取模
	static long binpowmod(long x,long n,long MOD) {
		x %= MOD;
		long res = 1;
	    while (n > 0) {
	        if ((n & 1) == 1) {
	            res = res * x % MOD;
	        }
	        x = x * x % MOD;
	        n >>= 1;
	    }
	    return res;
	}
}
